package com.solming.leetcode.question;

public class ReverseStr541 {

    public static String reverseStr(String s, int k) {
        int len = s.length();
        char[] chars = s.toCharArray();
        int i = 0;
        while (i < len) {
            int start = i;
            int end = i + k - 1;
            end = Math.min(end, len-1);
            while (start < end ) {
                char c = chars[start];
                chars[start] = chars[end];
                chars[end] = c;
                start++;
                end--;

            }
            i += 2 * k;
        }
        return new String(chars);
    }


    public static void main(String[] args) {
        System.out.println(reverseStr("abcdefg", 8));
        System.out.println("gfedcba");
    }
}
